package net.tv90.bfmccore.listener;

import net.tv90.bfmccore.Enum.EnumUnlock;
import net.tv90.bfmccore.event.AttachmentUnlockEvent;
import net.tv90.bfmccore.event.RibbonUnlockEvent;
import net.tv90.bfmccore.event.UnlockEvent;
import net.tv90.bfmccore.unlock.UnlockUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;

import java.util.HashMap;

public class UnlockListener implements Listener {

    public void playSound(Player p){
        p.playSound(p.getLocation(), "custom.Awards_Unlock", 10.0F, 1.0F);
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onUnlock(UnlockEvent e) {
        Player p = e.getPlayer();
        String weapon = e.getWeapon();
        int count = e.getCount();
        HashMap<String, Integer> map = e.getMap();

        if(weapon == null) return;

        //主武器解锁
        if (weapon.equalsIgnoreCase("PHANTOM CROSSBOW") && count >= 30 && !p.hasPermission("fms.slain.crossbow")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.crossbow true");
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.crossbow1 true");
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.crossbow2 true");
            p.sendMessage("§e[解锁提示]你已经获得了细头/爆炸弩箭的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","BULLETPOINT ARROW");
            UnlockUtil.showItemHUD(p, "weapon","EXPLOSIVE ARROW");
        }
        if ((map.get("TYPE-81M LMG") != null && map.get("TYPE-81M LMG") >= 50) && (map.get("QBZ-81-1") != null && map.get("QBZ-81-1") >= 50)
                && !p.hasPermission("fms.slain.cslr14")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.cslr14 true");
            p.sendMessage("§e[解锁提示]你已经获得了CS-LR14的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","CS-LR14");
        }
        if ((map.get("AK-12U") != null && map.get("AK-12U") >= 50) && (map.get("AS VAL") != null && map.get("AS VAL") >= 50)
                && !p.hasPermission("fms.slain.am17")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.am17 true");
            p.sendMessage("§e[解锁提示]你已经获得了AM-17的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","AM-17");
        }
        if (weapon.equalsIgnoreCase("F2000") && count >= 100 && !p.hasPermission("fms.slain.p90")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.p90 true");
            p.sendMessage("§e[解锁提示]你已经获得了P90的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","P90");
        }
        if (weapon.equalsIgnoreCase("MP9") && count >= 100 && !p.hasPermission("fms.slain.apc9k")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.apc9k true");
            p.sendMessage("§e[解锁提示]你已经获得了APC-9K的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","APC-9K");
        }
        if ((map.get("MP5SD") != null && map.get("MP5SD") >= 50) && (map.get("MP7") != null && map.get("MP7") >= 50)
                && !p.hasPermission("fms.slain.honeybadger")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.honeybadger true");
            p.sendMessage("§e[解锁提示]你已经获得了.300 LVC的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon",".300 LVC");
        }
        if ((map.get("SV-98") != null && map.get("SV-98") >= 50) && (map.get("SVD-12") != null && map.get("SVD-12") >= 50)
                && !p.hasPermission("fms.slain.t5000")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.t5000 true");
            p.sendMessage("§e[解锁提示]你已经获得了T-5000的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","T-5000");
        }
        if (weapon.equalsIgnoreCase("MDR") && count >= 50 && !p.hasPermission("fms.slain.mdr762")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mdr762 true");
            p.sendMessage("§e[解锁提示]你已经获得了MDR 762的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MDR");
        }

        //道具解锁
        if (weapon.equalsIgnoreCase("M26 MASS") && count >= 30 && !p.hasPermission("fms.slain.m26slug")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m26slug true");
            p.sendMessage("§e[解锁提示]你已经获得了M26 SLUG的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","M26 SLUG");
        }
        if (weapon.equalsIgnoreCase("M84 Flashbang") && count >= 5 && !p.hasPermission("fms.slain.ds3decoy")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.ds3decoy true");
            p.sendMessage("§e[解锁提示]你已经获得了DS3 Decoy的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","DS-3 Decoy");
        }
        if (weapon.equalsIgnoreCase("M26 SLUG") && count >= 30 && !p.hasPermission("fms.slain.m26frag")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m26frag true");
            p.sendMessage("§e[解锁提示]你已经获得了M26 FRAG的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","M26 SLUG");
        }
        if (weapon.equalsIgnoreCase("M4 MAAWS") && count >= 30 && !p.hasPermission("fms.slain.m4cghe")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m4cghe true");
            p.sendMessage("§e[解锁提示]你已经获得了M4CG HEAT的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","M4CG Recoilless");
        }
        if ((map.get("FIM-92 Stringer") != null && map.get("FIM-92 Stringer") >= 10) && (map.get("SA-18 IGLA") != null && map.get("SA-18 IGLA") >= 10)
                && !p.hasPermission("fms.slain.aamine")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.aamine true");
            p.sendMessage("§e[解锁提示]你已经获得了AA Mine的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","AA Mine");
        }
        if ((map.get("C4 Explosive") != null && map.get("C4 Explosive") >= 5) && (map.get("40mm HE") != null && map.get("40mm HE") >= 5)
                && !p.hasPermission("fms.slain.rdxass")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.rdxass true");
            p.sendMessage("§e[解锁提示]你已经获得了RDX DEMOPAK[突击兵]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","RDX DEMOPAK");
        }
        if ((map.get("C4 Explosive") != null && map.get("C4 Explosive") >= 5) && (map.get("Timing Bomb") != null && map.get("Timing Bomb") >= 5)
                && !p.hasPermission("fms.slain.rdxeng")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.rdxeng true");
            p.sendMessage("§e[解锁提示]你已经获得了RDX DEMOPAK[工程兵]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","RDX DEMOPAK");
        }
        if (weapon.equalsIgnoreCase("QN202") && count >= 30 && !p.hasPermission("fms.slain.qn202he")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.qn202he true");
            p.sendMessage("§e[解锁提示]你已经获得了QN202 HE的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","QN202");
        }
        if (weapon.equalsIgnoreCase("APS Grenade") && count >= 1 && !p.hasPermission("fms.slain.mpapsv2")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mpapsv2 true");
            p.sendMessage("§e[解锁提示]你已经获得了MP-APS-V2高级主动防御系统的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MP-APS-V2");
        }
        if (weapon.equalsIgnoreCase("Light Mortar") && count >= 10 && !p.hasPermission("fms.slain.60mmabrst")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.60mmabrst true");
            p.sendMessage("§e[解锁提示]你已经获得了60mm轻型掷弹筒[空爆弹]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Light Mortar");
        }
        if (weapon.equalsIgnoreCase("SG-34 Sentry Gun") && count >= 30 && !p.hasPermission("fms.slain.sg36")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.sg36 true");
            p.sendMessage("§e[解锁提示]你已经获得了SG-36哨兵炮的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","SG-36 Sentry Gun");
        }

        //近战解锁
        if (weapon.equalsIgnoreCase("AS VAL") && count >= 100 && !p.hasPermission("fms.slain.machete")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.machete true");
            p.sendMessage("§e[解锁提示]你已经获得了砍刀的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MACHETE");
        }
        if (weapon.equalsIgnoreCase("M4A1") && count >= 100 && !p.hasPermission("fms.slain.shovel")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.shovel true");
            p.sendMessage("§e[解锁提示]你已经获得了军用铲的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MILITARY SHOVEL");
        }
        if (weapon.equalsIgnoreCase("AK-74M") && count >= 100 && !p.hasPermission("fms.slain.mpl50")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mpl50 true");
            p.sendMessage("§e[解锁提示]你已经获得了MPL-50工兵铲的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MPL-50");
        }
        if (weapon.equalsIgnoreCase("Type-81M LMG") && count >= 100 && !p.hasPermission("fms.slain.type56")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.type56 true");
            p.sendMessage("§e[解锁提示]你已经获得了56式三棱军刺的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","TYPE-56 SPIKE");
        }
        if (weapon.equalsIgnoreCase("QBZ-95-1") && count >= 100 && !p.hasPermission("fms.slain.wjq308")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.wjq308 true");
            p.sendMessage("§e[解锁提示]你已经获得了WJQ-308工兵铲的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","WJQ-308");
        }

        //手榴弹解锁
        if (((weapon.equalsIgnoreCase("M67 Frag")) ||
                (weapon.equalsIgnoreCase("TYPE-82 Frag")) ||
                (weapon.equalsIgnoreCase("RGD-5 Frag"))) && map.get("Grenade") >= 30 && !p.hasPermission("fms.slain.v40")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.v40 true");
            p.sendMessage("§e[解锁提示]你已经获得了V40迷你手榴弹的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","V40 Mini");
        }
        if (weapon.equalsIgnoreCase("V40 Mini") && count >= 30 && !p.hasPermission("fms.slain.rgo")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.rgo true");
            p.sendMessage("§e[解锁提示]你已经获得了RGO碰炸手榴弹的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","RGO Impact");
        }
        if (weapon.equalsIgnoreCase("M34 Incendiary") && count >= 30 && !p.hasPermission("fms.slain.molotov")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.molotov true");
            p.sendMessage("§e[解锁提示]你已经获得了燃烧瓶的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Molotov");
        }

        //副武器解锁
        if (weapon.equalsIgnoreCase("QSZ-92") && count >= 30 && !p.hasPermission("fms.slain.type54")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.type54 true");
            p.sendMessage("§e[解锁提示]你已经获得了54式手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","TYPE-54");
        }
        if (weapon.equalsIgnoreCase("TYPE-54") && count >= 30 && !p.hasPermission("fms.slain.np22")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.np22 true");
            p.sendMessage("§e[解锁提示]你已经获得了NP22手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","NP22");
        }
        if (weapon.equalsIgnoreCase("NP22") && count >= 30 && !p.hasPermission("fms.slain.nrp357")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.nrp357 true");
            p.sendMessage("§e[解锁提示]你已经获得了NRP-357手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","NRP-357");
        }
        if (weapon.equalsIgnoreCase("NRP-357") && count >= 30 && !p.hasPermission("fms.slain.np7")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.np7 true");
            p.sendMessage("§e[解锁提示]你已经获得了NP7手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","NP7");
        }
        if (weapon.equalsIgnoreCase("MP-443") && count >= 30 && !p.hasPermission("fms.slain.mp412")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mp412 true");
            p.sendMessage("§e[解锁提示]你已经获得了MP412 REX手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MP412 REX");
        }
        if (weapon.equalsIgnoreCase("MP412 REX") && count >= 30 && !p.hasPermission("fms.slain.44magnum")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.44magnum true");
            p.sendMessage("§e[解锁提示]你已经获得了.44 Magnum手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon",".44 Magnum");
        }
        if (weapon.equalsIgnoreCase(".44 Magnum") && count >= 30 && !p.hasPermission("fms.slain.aps")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.aps true");
            p.sendMessage("§e[解锁提示]你已经获得了斯捷奇金APS-M手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","APS-M");
        }
        if (weapon.equalsIgnoreCase("M9") && count >= 30 && !p.hasPermission("fms.slain.m327")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m327 true");
            p.sendMessage("§e[解锁提示]你已经获得了SW M327手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","SW M327");
        }
        if (weapon.equalsIgnoreCase("SW M327") && count >= 30 && !p.hasPermission("fms.slain.deagle44")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.deagle44 true");
            p.sendMessage("§e[解锁提示]你已经获得了DEAGLE 44手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","DEAGLE 44");
        }
        if (weapon.equalsIgnoreCase("M9") && count >= 60 && !p.hasPermission("fms.slain.m45a1")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m45a1 true");
            p.sendMessage("§e[解锁提示]你已经获得了M45A1手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","M45A1");
        }
        if (weapon.equalsIgnoreCase("DEAGLE 44") && count >= 30 && !p.hasPermission("fms.slain.g18")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.g18 true");
            p.sendMessage("§e[解锁提示]你已经获得了G18手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","GLOCK-18");
        }

        if (weapon.equalsIgnoreCase("M45A1") && count >= 50 && !p.hasPermission("fms.slain.compact45")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.compact45 true");
            p.sendMessage("§e[解锁提示]你已经获得了Compact 45手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Compact 45");
        }
        if (weapon.equalsIgnoreCase("BALD EAGLE") && count >= 30 && !p.hasPermission("fms.slain.j941")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.j941 true");
            p.sendMessage("§e[解锁提示]你已经获得了Jericho 941手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Jericho 941");
        }
        if (weapon.equalsIgnoreCase(".44 Magnum") && count >= 100 && !p.hasPermission("fms.slain.rsh12")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.rsh12 true");
            p.sendMessage("§e[解锁提示]你已经获得了RSH-12手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","RSH-12");
        }
        if (weapon.equalsIgnoreCase("SW M327") && count >= 100 && !p.hasPermission("fms.slain.m500")) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m500 true");
            p.sendMessage("§e[解锁提示]你已经获得了SW M500手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","SW M500");
        }

        boolean bl = map.get("40mm Frag") != null && map.get("40mm HE") != null &&
                map.get("40mm Smoke") != null && map.get("40mm PoisonGas") != null && map.get("40mm LVG") != null && map.get("40mm Flashbang") != null;
        if (!p.hasPermission("fms.slain.40mm3gl") && bl && map.get("40mm Frag") >= 3 && map.get("40mm HE") >= 3 &&
                map.get("40mm Smoke") >= 3 && map.get("40mm PoisonGas") >= 3 && map.get("40mm LVG") >= 3 && map.get("40mm Flashbang") >= 3) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.40mm3gl true");
            p.sendMessage("§e[解锁提示]你已经获得了40mm3GL的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","40mm 3GL");
        }

        if (p.hasPermission("unlock.suav") && !p.hasPermission("fms.slain.ucav")) {
            if (weapon.equalsIgnoreCase("Active Radar UAV") && count >= 20) {
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.ucav true");
                p.sendMessage("§e[解锁提示]你已经获得了UCAV的解锁权限");
                UnlockUtil.showItemHUD(p, "weapon","UCAV");
            }
        }
        if (p.hasPermission("unlock.ucav") && !p.hasPermission("fms.slain.uav1")) {
            if ((weapon.equalsIgnoreCase("M40A5") || weapon.equalsIgnoreCase("SV-98")) || weapon.equalsIgnoreCase("CS-LR4")) {
                if (map.get("M40A5") != null && map.get("SV-98") != null && map.get("CS-LR4") != null &&
                        map.get("M40A5") >= 10 && map.get("SV-98") >= 10 && map.get("CS-LR4") >= 10) {
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.uav1 true");
                    p.sendMessage("§e[解锁提示]你已经获得了UAV-1的解锁权限");
                }
            }
        }
        if (p.hasPermission("unlock.m4cgap") && !p.hasPermission("fms.slain.m4cgab")) {
            if (weapon.equalsIgnoreCase("XM25 Airburst") && count >= 30) {
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.m4cgab true");
                p.sendMessage("§e[解锁提示]你已经获得了M4CG Airburst的解锁权限");
                UnlockUtil.showItemHUD(p, "weapon","M4CG Recoilless");
            }
        }
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onRibbonUnlock(RibbonUnlockEvent e) {
        Player p = e.getPlayer();
        int count = e.getRibbonCount();
        String ribbonType = e.getRibbonType();
        HashMap<String, Integer> map = e.getRibbonMap();
        if (!p.hasPermission("fms.slain.combataxe") && ribbonType.equals("Ribbon_ME") && count >= 10) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.combataxe true");
            p.sendMessage("§e[解锁提示]你已经获得了战斗飞斧的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Combat Axe");
        }
        if (!p.hasPermission("fms.slain.g17") && ribbonType.equals("Ribbon_HG") && count >= 15) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.g17 true");
            p.sendMessage("§e[解锁提示]你已经获得了G17手枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","GLOCK-17");
        }
        if (!p.hasPermission("fms.slain.sawedoff") && !p.hasPermission("fms.slain.shorty12g")
                && map.get(p.getName() + "_SG_Ribbon") != null && map.get(p.getName() + "_HG_Ribbon") != null
                && map.get(p.getName() + "_SG_Ribbon") >= 15 && map.get(p.getName() + "_HG_Ribbon") >= 20) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.sawedoff true");
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.shorty12g true");
            p.sendMessage("§e[解锁提示]你已经获得了Shorty-12G的解锁权限");
            p.sendMessage("§e[解锁提示]你已经获得了短截式猎枪的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Shorty 12G");
            UnlockUtil.showItemHUD(p, "weapon","SAWED-OFF");
        }
        if (!p.hasPermission("fms.slain.tugs") && ribbonType.equals("Ribbon_Farshoot") && count >= 3) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.tugs true");
            p.sendMessage("§e[解锁提示]你已经获得了T-UGS的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","T-UGS");
        }

        if (!p.hasPermission("fms.slain.60mmap") &&
                map.get(p.getName() + "_Mortar_Ribbon") != null && map.get(p.getName() + "_ATW_Ribbon") != null &&
                map.get(p.getName() + "_Mortar_Ribbon") >= 1 && map.get(p.getName() + "_ATW_Ribbon") >= 1) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.60mmap true");
            p.sendMessage("§e[解锁提示]你已经获得了60mm轻型掷弹筒[穿甲弹]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Light Mortar");
        }

        if (!p.hasPermission("fms.slain.60mmhe") &&
                map.get(p.getName() + "_Mortar_Ribbon") != null && map.get(p.getName() + "_EXP_Ribbon") != null &&
                map.get(p.getName() + "_Mortar_Ribbon") >= 1 && map.get(p.getName() + "_EXP_Ribbon") >= 1) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.60mmhe true");
            p.sendMessage("§e[解锁提示]你已经获得了60mm轻型掷弹筒[高爆弹]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Light Mortar");
        }

        if (!p.hasPermission("fms.slain.4axisdronerpg") &&
                map.get(p.getName() + "_Bomber_Ribbon") != null && map.get(p.getName() + "_ATW_Ribbon") != null &&
                map.get(p.getName() + "_Bomber_Ribbon") >= 3 && map.get(p.getName() + "_ATW_Ribbon") >= 5) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.4axisdronerpg true");
            p.sendMessage("§e[解锁提示]你已经获得了四轴无人机[RPG]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","4-AXIS-DRONE");
        }

        if (!p.hasPermission("fms.slain.4axisdronegrenade") &&
                map.get(p.getName() + "_Bomber_Ribbon") != null && map.get(p.getName() + "_EXP_Ribbon") != null &&
                map.get(p.getName() + "_Bomber_Ribbon") >= 3 && map.get(p.getName() + "_EXP_Ribbon") >= 5) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.4axisdronegrenade true");
            p.sendMessage("§e[解锁提示]你已经获得了四轴无人机[榴弹]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","4-AXIS-DRONE");
        }

        if (!p.hasPermission("fms.slain.4axisdroneshotgun") &&
                map.get(p.getName() + "_Bomber_Ribbon") != null && map.get(p.getName() + "_SG_Ribbon") != null &&
                map.get(p.getName() + "_Bomber_Ribbon") >= 3 && map.get(p.getName() + "_SG_Ribbon") >= 10) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.4axisdroneshotgun true");
            p.sendMessage("§e[解锁提示]你已经获得了四轴无人机[霰弹]的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","4-AXIS-DRONE");
        }

        if (!p.hasPermission("fms.slain.mp9") &&
                map.get(p.getName() + "_Ammo_Ribbon") != null && map.get(p.getName() + "_Heal_Ribbon") != null &&
                map.get(p.getName() + "_Ammo_Ribbon") >= 3 && map.get(p.getName() + "_Heal_Ribbon") >= 3) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mp9 true");
            p.sendMessage("§e[解锁提示]你已经获得了MP9的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MP9");
        }

        if (!p.hasPermission("fms.slain.mcx") && ribbonType.equals("Ribbon_GunMaster") && count >= 3) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mcx true");
            p.sendMessage("§e[解锁提示]你已经获得了MCX SPEAR的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MCX SPEAR");
        }

        if (!p.hasPermission("fms.slain.mpx") && ribbonType.equals("Ribbon_SMG") && count >= 20) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.mpx true");
            p.sendMessage("§e[解锁提示]你已经获得了MPX的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","MPX");
        }

        if (!p.hasPermission("fms.slain.l115") && ribbonType.equals("Ribbon_Farshoot") && count >= 5) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.l115 true");
            p.sendMessage("§e[解锁提示]你已经获得了L115的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","L115");
        }

        if (!p.hasPermission("fms.slain.dsr1") && ribbonType.equals("Ribbon_SR") && count >= 20) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.dsr1 true");
            p.sendMessage("§e[解锁提示]你已经获得了DSR-1的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","DSR-1");
        }

        if (!p.hasPermission("fms.slain.atgrenade") && ribbonType.equals("Ribbon_MBT") && count >= 5) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.atgrenade true");
            p.sendMessage("§e[解锁提示]你已经获得了反坦克手榴弹的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","AT Grenade");
        }

        if (!p.hasPermission("fms.slain.abgrenade") && ribbonType.equals("Ribbon_Headshot") && count >= 10) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.abgrenade true");
            p.sendMessage("§e[解锁提示]你已经获得了弹跳空爆手雷的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","Airburst Grenade");
        }

        if (!p.hasPermission("fms.slain.apsgrenade") && ribbonType.equals("Ribbon_PreventLinkedKill") && count >= 5) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain.apsgrenade true");
            p.sendMessage("§e[解锁提示]你已经获得了激光拦截手雷的解锁权限");
            UnlockUtil.showItemHUD(p, "weapon","APS Grenade");
        }
    }

    @EventHandler
    public void onWeaponTypeUnlock(AttachmentUnlockEvent e) {
        Player p = e.getPlayer();
        int count = e.getWeaponCount();
        String type = e.getWeaponType();

        if (type.startsWith("US")) {

            if (type.equals("USSR") && count % 15 == 0 && count <= 325) {
                for (EnumUnlock.EnumUnlock_US_SR value : EnumUnlock.EnumUnlock_US_SR.values()) {
                    if ((count / 15 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_sr true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国狙击步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("USDMR") && count % 20 == 0 && count <= 540) {
                for (EnumUnlock.EnumUnlock_US_DMR value : EnumUnlock.EnumUnlock_US_DMR.values()) {
                    if ((count / 20 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_dmr true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国射手步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("USAR") && count % 30 == 0 && count <= 630) {
                for (EnumUnlock.EnumUnlock_US_AR value : EnumUnlock.EnumUnlock_US_AR.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_ar true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国突击步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("USCR") && count % 30 == 0 && count <= 630) {
                for (EnumUnlock.EnumUnlock_US_CR value : EnumUnlock.EnumUnlock_US_CR.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_cr true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国卡宾步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("USSMG") && count % 30 == 0 && count <= 600) {
                for (EnumUnlock.EnumUnlock_US_SMG value : EnumUnlock.EnumUnlock_US_SMG.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_smg true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国冲锋枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("USSG") && count % 25 == 0 && count <= 650) {
                for (EnumUnlock.EnumUnlock_US_SG value : EnumUnlock.EnumUnlock_US_SG.values()) {
                    if ((count / 25 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_sg true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国霰弹枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("USLMG") && count % 30 == 0 && count <= 660) {
                for (EnumUnlock.EnumUnlock_US_LMG value : EnumUnlock.EnumUnlock_US_LMG.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_us_lmg true");
                        p.sendMessage("§e[解锁提示]你已经获得了美国轻机枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
        }

        else if (type.startsWith("RU")) {

            if (type.equals("RUSR") && count % 15 == 0 && count <= 325) {
                for (EnumUnlock.EnumUnlock_RU_SR value : EnumUnlock.EnumUnlock_RU_SR.values()) {
                    if ((count / 15 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_sr true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国狙击步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("RUDMR") && count % 20 == 0 && count <= 540) {
                for (EnumUnlock.EnumUnlock_RU_DMR value : EnumUnlock.EnumUnlock_RU_DMR.values()) {
                    if ((count / 20 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_dmr true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国射手步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("RUAR") && count % 30 == 0 && count <= 630) {
                for (EnumUnlock.EnumUnlock_RU_AR value : EnumUnlock.EnumUnlock_RU_AR.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_ar true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国突击步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("RUCR") && count % 30 == 0 && count <= 630) {
                for (EnumUnlock.EnumUnlock_RU_CR value : EnumUnlock.EnumUnlock_RU_CR.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_cr true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国卡宾步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("RUSMG") && count % 30 == 0 && count <= 600) {
                for (EnumUnlock.EnumUnlock_RU_SMG value : EnumUnlock.EnumUnlock_RU_SMG.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_smg true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国冲锋枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("RUSG") && count % 25 == 0 && count <= 650) {
                for (EnumUnlock.EnumUnlock_RU_SG value : EnumUnlock.EnumUnlock_RU_SG.values()) {
                    if ((count / 25 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_sg true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国霰弹枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("RULMG") && count % 30 == 0 && count <= 660) {
                for (EnumUnlock.EnumUnlock_RU_LMG value : EnumUnlock.EnumUnlock_RU_LMG.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_ru_lmg true");
                        p.sendMessage("§e[解锁提示]你已经获得了俄国轻机枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
        }
        else if (type.startsWith("CN")) {

            if (type.equals("CNSR") && count % 15 == 0 && count <= 325) {
                for (EnumUnlock.EnumUnlock_CN_SR value : EnumUnlock.EnumUnlock_CN_SR.values()) {
                    if ((count / 15 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_sr true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国狙击步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("CNDMR") && count % 20 == 0 && count <= 540) {
                for (EnumUnlock.EnumUnlock_CN_DMR value : EnumUnlock.EnumUnlock_CN_DMR.values()) {
                    if ((count / 20 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_dmr true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国射手步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("CNAR") && count % 30 == 0 && count <= 630) {
                for (EnumUnlock.EnumUnlock_CN_AR value : EnumUnlock.EnumUnlock_CN_AR.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_ar true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国突击步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("CNCR") && count % 30 == 0 && count <= 630) {
                for (EnumUnlock.EnumUnlock_CN_CR value : EnumUnlock.EnumUnlock_CN_CR.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_cr true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国卡宾步枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("CNSMG") && count % 30 == 0 && count <= 600) {
                for (EnumUnlock.EnumUnlock_CN_SMG value : EnumUnlock.EnumUnlock_CN_SMG.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_smg true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国冲锋枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("CNSG") && count % 25 == 0 && count <= 650) {
                for (EnumUnlock.EnumUnlock_CN_SG value : EnumUnlock.EnumUnlock_CN_SG.values()) {
                    if ((count / 25 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_sg true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国霰弹枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
            else if (type.equals("CNLMG") && count % 30 == 0 && count <= 660) {
                for (EnumUnlock.EnumUnlock_CN_LMG value : EnumUnlock.EnumUnlock_CN_LMG.values()) {
                    if ((count / 30 - 1) == value.ordinal()) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + p.getName() + " permission set fms.slain." + value.get() + "_cn_lmg true");
                        p.sendMessage("§e[解锁提示]你已经获得了中国轻机枪" + value.getLang_CN() + "的解锁权限");
                        playSound(p);
                    }
                }
            }
        }
    }
}
